#include "lxz_config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "lxz_types.h"
#include "os_port.h"
#include "lxz_runlog.h"
#include "lxz_debug.h"
#include "lxz_ring.h"
#include "lxz_string.h"
#include "lxz_dstring.h"
#include "lxz_atc_req.h"
#include "lxz_urc_table.h"
#include "lxz_ccore_cmd.h"
#include "lxz_hwip_cmd.h"
#include "lxz_dbg_vmem.h"


static sint32 lxzat_caret_curc_init(void * pctxt);
static sint32 lxzat_caret_curc_req(void * pctxt);
static sint32 lxzat_caret_curc_resp(void * pctxt);
static sint32 lxzat_caret_curc_reset(void * pctxt);

static sint32 lxzat_caret_ipinit_init(void * pctxt);
static sint32 lxzat_caret_ipinit_req(void * pctxt);
static sint32 lxzat_caret_ipinit_resp(void * pctxt);
static sint32 lxzat_caret_ipinit_reset(void * pctxt);

static sint32 lxzat_caret_ipopen_init(void * pctxt);
static sint32 lxzat_caret_ipopen_req(void * pctxt);
static sint32 lxzat_caret_ipopen_resp(void * pctxt);
static sint32 lxzat_caret_ipopen_reset(void * pctxt);

static sint32 lxzat_caret_ipsend_init(void * pctxt);
static sint32 lxzat_caret_ipsend_req(void * pctxt);
static sint32 lxzat_caret_ipsend_resp(void * pctxt);
static sint32 lxzat_caret_ipsend_reset(void * pctxt);

static sint32 lxzat_caret_ipclose_init(void * pctxt);
static sint32 lxzat_caret_ipclose_req(void * pctxt);
static sint32 lxzat_caret_ipclose_resp(void * pctxt);
static sint32 lxzat_caret_ipclose_reset(void * pctxt);

static sint32 lxzat_caret_ipsendex_init(void * pctxt);
static sint32 lxzat_caret_ipsendex_req(void * pctxt);
static sint32 lxzat_caret_ipsendex_resp(void * pctxt);
static sint32 lxzat_caret_ipsendex_reset(void * pctxt);

static sint32 lxzat_hwip_socket_f_close(sint32 i_socket_id);

static sint32 lxzat_callback_ipinit_f_exec(sint32 p1, sint32 p2);
static sint32 lxzat_callback_ipinit_f_exit(sint32 p1, sint32 p2);
static sint32 lxzat_task_ipinit_newtask(sint32 i_id_vspctxt, sint32 i_id_pdpctxt);

static sint32 lxzat_callback_ipdata_tcpclient_f_exec(sint32 p1, sint32 p2);
static sint32 lxzat_callback_ipdata_tcpclient_f_exit(sint32 p1, sint32 p2);
static sint32 lxzat_task_ipdata_tcpclient_newtask(sint32 i_id_socket, sint32 i_id_vspctxt);

static sint32 gs_hwip_urcflag = 1;

typedef struct _lxzat_hwip_socket_t
{
    sint32 it_vsp_id;      /* Serial-Port ID */
    sint32 it_nif_id;      /* Network-Interface ID */
    uint16 ut_local_port;  /* The Port of local-host */
    uint16 ut_peer_port;   /* The Port of remote-host */
    uint32 it_link_type;   /* The type of link, TCP or UDP */
    sint32 it_socket_fd;   /* The file description of socket */
    sint32 it_socket_phase;/* The phase of socket, IDLE,OPEN... etc */
    sint32 it_urc_flag;    /* URC flag, OFF by default */
    sint32 it_urc_view;    /* TXT or PDU, valid when URC is valid */
    sint32 it_urc_read;
    sint32 it_urc_time;
    sint32 it_rxdata_len;  /* the length of data that stored in rxbuf */
    sint32 it_rxbuf_size;  /* The size of rxbuf */
    sint32 it_txdata_len;  /* the length of data that stored in txbuf */
    sint32 it_txbuf_size;  /* The size of txbuf */
    uint08 * pt_rxbuf;     /* pointer of rxbuf */
    uint08 * pt_txbuf;     /* pointer of rxbuf */
    uint08 * pt_peer_ip;   /* The IP-Address of remote-host */
	uint08 * pt_peer_url;  /* The Domain-Name of remote-host */
	uint08 * pt_local_ip;  /* The IP-Address of remote-host */
}lxzat_hwip_socket_t;

static lxzat_hwip_socket_t gs_hwip_socket_pool[LXZAT_HWIP_MAX_NUM] = {0};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_caret_curc =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "^CURC", 
    lxzat_caret_curc_init,
    lxzat_caret_curc_req,
    lxzat_caret_curc_resp,
    lxzat_caret_curc_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_caret_ipinit =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "^IPINIT", 
    lxzat_caret_ipinit_init,
    lxzat_caret_ipinit_req,
    lxzat_caret_ipinit_resp,
    lxzat_caret_ipinit_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_caret_ipopen =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "^IPOPEN", 
    lxzat_caret_ipopen_init,
    lxzat_caret_ipopen_req,
    lxzat_caret_ipopen_resp,
    lxzat_caret_ipopen_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_caret_ipsend =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "^IPSEND", 
    lxzat_caret_ipsend_init,
    lxzat_caret_ipsend_req,
    lxzat_caret_ipsend_resp,
    lxzat_caret_ipsend_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_caret_ipclose =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "^IPCLOSE", 
    lxzat_caret_ipclose_init,
    lxzat_caret_ipclose_req,
    lxzat_caret_ipclose_resp,
    lxzat_caret_ipclose_reset
};

/*
 *  Description:
 *    A caplets for hiding concrete implementation.
 *  Note: 
 *    Please do not change any part of current piece when you unsure.
 */
const lxzat_info_t lai_caret_ipsendex =
{
    LXZAT_TYPE_RANGE_LOCAL|LXZAT_TYPE_STRING_EXTEND,
    "^IPSENDEX", 
    lxzat_caret_ipsendex_init,
    lxzat_caret_ipsendex_req,
    lxzat_caret_ipsendex_resp,
    lxzat_caret_ipsendex_reset
};

/*
 *  Description:
 *    The initialize handler of "AT^CURC".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_curc_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT^CURC".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_curc_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;

    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_curc_req,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_curc_req,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    i_req_type = p_cur_req->it_req_type;
    switch (i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            sint32 i_new_urcflag = 0;

            if (p_cur_req->it_nb_param != 1)
            {
                OS_DBG_LOG(("lxzat_caret_curc_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }

            i_new_urcflag = PARAM1(p_cur_req).it_number;
            if ((i_new_urcflag != 0) && (i_new_urcflag != 1))
            {
                OS_DBG_LOG(("lxzat_dollar_myneturc_req,i_new_urcflag:%d\r\n",i_new_urcflag));
                return E_LEC_ERR_P_OTHER;
            }

            gs_hwip_urcflag = i_new_urcflag;
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }

    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT^CURC".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_curc_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;

    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_curc_resp,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_curc_resp,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    i_req_type = p_cur_req->it_req_type;
    switch (i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: %d",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                gs_hwip_urcflag);

            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: (0,1)",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);

            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }

    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT^CURC".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_curc_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT^IPINIT".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipinit_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT^IPINIT".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipinit_req(void * pctxt)
{
    LXZAT_ERROR_CODE_E e_err_code = E_LEC_OK;

    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_pdpcfg_t * p_cur_pdpcfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipinit_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipinit_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    i_req_type = p_cur_req->it_req_type;
    switch (i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            sint32 i_id_pdpctxt = 1;
            sint32 i_creg_isready = 0;
            sint32 i_pdp_isactive = 0;

            if (p_cur_req->it_nb_param != 1)
            {
                OS_DBG_LOG(("lxzat_caret_ipinit_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }

            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_STRING)
            {
                OS_DBG_LOG(("lxzat_caret_ipinit_req,param1 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_creg_isready = lxzat_creg_f_getstatus(p_cur_spcfg->i_vsp_id);
            if(i_creg_isready == 0)
            {
                return E_LEC_SGCC_PDP_ACTIVE_REJECT;
            }
            
            lxzat_pdpinfo_f_getstatus(i_id_pdpctxt, &i_pdp_isactive);
            if (E_PDP_STATUS_ACTIVATING == i_pdp_isactive)
            {
                return E_LEC_SGCC_PDP_ACTIVE_REJECT;
            }
            if (E_PDP_STATUS_ACTIVATED == i_pdp_isactive)
            {
                return E_LEC_SGCC_PDP_ACTIVED;
            }
            
            lxzat_pdpinfo_f_active(p_cur_spcfg->i_vsp_id, i_id_pdpctxt);
            lxzat_task_ipinit_newtask(p_cur_spcfg->i_vsp_id, i_id_pdpctxt);

            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }

    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }

    default:
        {
            e_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }

    return e_err_code;
}

/*
 *  Description:
 *    The response handler of "AT^IPINIT".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipinit_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;

    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipinit_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipinit_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_SGCC_UNKNOWN;
    }

    i_req_type = p_cur_req->it_req_type;
    switch (i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            break;
        }

    case LXZAT_REQ_TYPE_READ:
        {
            sint32 i = 0;
            lxzat_pdpinfo_t* p_cur_pdpinfo = NULL;

            while (i < 6)
            {
                p_cur_pdpinfo = lxzat_pdpinfo_f_get(i + 1);
                if (E_PDP_STATUS_ACTIVATED == p_cur_pdpinfo->it_pdp_state)
                {
                    lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                        LXZAT_RSP_MODE_P1N0,
                        "%s: %d,1,\"%s\"",
                        p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                        i,
                        p_cur_pdpinfo->pt_ip_host);
                }

                i = i + 1;
            }
            break;
        }

    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <\"APN\">",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            break;
        }


    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }

    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT^IPINIT".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipinit_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT^IPOPEN".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipopen_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT^IPOPEN".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipopen_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

	sint32 i_op_status = LXZAT_FALSE;
    sint32 i_socket_id = 0;
    sint32 i_nb_bytes = 0;
    lxzat_hwip_socket_t * p_hwip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipopen_req,p_lxzat_ctxt is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipopen_req,p_cur_req or p_cur_spcfg is NULL\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 4)
            {
                OS_DBG_LOG(("lxzat_caret_ipopen_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
            
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_caret_ipopen_req,param1 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_STRING)
            {
                OS_DBG_LOG(("lxzat_caret_ipopen_req,param2 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM3_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_STRING)
            {
                OS_DBG_LOG(("lxzat_caret_ipopen_req,param3 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }

            if (PARAM4_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_caret_ipopen_req,param4 type is error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_socket_id = PARAM1(p_lxzat_ctxt->pt_req_data).it_number;
            if(i_socket_id < 0 || i_socket_id > LXZAT_HWIP_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_caret_ipopen_req,i_socket_id=%d\r\n", i_socket_id));
                return E_LEC_ERR_P_RANGE;
            }

            p_hwip_socket = &(gs_hwip_socket_pool[i_socket_id]);
            if (   (p_hwip_socket->it_socket_phase != E_HWIP_SOCKET_IDLE)
                && (p_hwip_socket->it_socket_phase != E_HWIP_SOCKET_SET))
            {
                OS_DBG_LOG(("lxzat_caret_ipopen_req,i_socket_phase=%d\r\n", p_hwip_socket->it_socket_phase));
                return E_LEC_ERR_NOT_ALLOWED;
            }
            
            /* Initialise hwip-socket, make sure all status is crystal clear  */
			lxzat_hwip_socket_f_close(i_socket_id);
			p_hwip_socket->it_socket_phase = E_HWIP_SOCKET_SET;
			
            p_hwip_socket->pt_rxbuf = (uint08 *)malloc(LXZAT_HWIP_TRYREAD_MAX);
            if(p_hwip_socket->pt_rxbuf == NULL)
            {
                lxzat_hwip_socket_f_close(i_socket_id);

                OS_DBG_LOG(("lxzat_caret_ipopen_req,pt_rxbuf malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }
			
            p_hwip_socket->pt_txbuf = (uint08 *)malloc(LXZAT_HWIP_TRYWRITE_MAX);
            if(p_hwip_socket->pt_txbuf == NULL)
            {
				lxzat_hwip_socket_f_close(i_socket_id);
				
                OS_DBG_LOG(("lxzat_caret_ipopen_req,pt_txbuf malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }

            p_hwip_socket->pt_peer_ip = (uint08 *)malloc(LXZAT_HWIP_IPSTRING_MAX);
            if(p_hwip_socket->pt_peer_ip == NULL)
            {
				lxzat_hwip_socket_f_close(i_socket_id);
				
                OS_DBG_LOG(("lxzat_caret_ipopen_req,pt_peer_ip malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }

            p_hwip_socket->pt_peer_url = (uint08 *)malloc(LXZAT_HWIP_URLSTRING_MAX);
            if(p_hwip_socket->pt_peer_url == NULL)
            {
				lxzat_hwip_socket_f_close(i_socket_id);

                OS_DBG_LOG(("lxzat_caret_ipopen_req,pt_peer_url malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }

            p_hwip_socket->pt_local_ip = (uint08 *)malloc(LXZAT_HWIP_IPSTRING_MAX);
            if(p_hwip_socket->pt_local_ip == NULL)
            {
				lxzat_hwip_socket_f_close(i_socket_id);

                OS_DBG_LOG(("lxzat_caret_ipopen_req,pt_local_ip malloc error\r\n"));
                return E_LEC_ERR_MEM_MALLOC;
            }

            if(0 == strcasecmp((char *)(PARAM2(p_cur_req).pt_str->pt_string), "UDP"))
            {
                p_hwip_socket->it_link_type = E_HWIP_LINK_UDP;
            }
            else if(0 == strcasecmp((char *)(PARAM2(p_cur_req).pt_str->pt_string), "TCP"))
            {
                p_hwip_socket->it_link_type = E_HWIP_LINK_TCP;
            }
            else
            {
				lxzat_hwip_socket_f_close(i_socket_id);

                OS_DBG_LOG(("lxzat_caret_ipopen_req,i_link_type=%s\r\n",PARAM2(p_cur_req).pt_str->pt_string));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_nb_bytes = PARAM3(p_cur_req).pt_str->it_length;
            if (i_nb_bytes > LXZAT_HWIP_URLSTRING_MAX)
            {
				lxzat_hwip_socket_f_close(i_socket_id);

                OS_DBG_LOG(("lxzat_caret_ipopen_req,i_url_length=%d\r\n", i_nb_bytes));
                return E_LEC_ERR_P_RANGE;
            }
            p_hwip_socket->pt_peer_url = (uint08 *)malloc(i_nb_bytes + 1);
            memset(p_hwip_socket->pt_peer_url, 0, i_nb_bytes + 1);
            strcpy(p_hwip_socket->pt_peer_url, PARAM3(p_cur_req).pt_str->pt_string);
            
            p_hwip_socket->ut_peer_port = (uint16)PARAM4(p_cur_req).it_number;
            if((p_hwip_socket->ut_peer_port < 0) || (p_hwip_socket->ut_peer_port > 0xFFFF))
            {
				lxzat_hwip_socket_f_close(i_socket_id);

                OS_DBG_LOG(("lxzat_caret_ipopen_req,u_peer_port=%d\r\n", p_hwip_socket->ut_peer_port));
                return E_LEC_ERR_P_RANGE;
            }

            switch(p_hwip_socket->it_link_type)
            {
            case E_HWIP_LINK_TCP:
                {
					i_op_status = osp_gethostbyname(p_hwip_socket->pt_peer_url, p_hwip_socket->pt_peer_ip);
                    if(LXZAT_TRUE != i_op_status)
                    {
						lxzat_hwip_socket_f_close(i_socket_id);

                        OS_DBG_LOG(("lxzat_caret_ipopen_req,osp_gethostbyname error\r\n"));
                        return E_LEC_SGCC_DNS_TIMEOUT;
                    }

                    p_hwip_socket->it_socket_fd = osp_socket_f_open(2/*AF_INET*/, 1/*SOCK_STREAM*/,0);
                    if (p_hwip_socket->it_socket_fd == LXZAT_HWIP_INVALID_FD)
                    {
						lxzat_hwip_socket_f_close(i_socket_id);
						
						OS_DBG_LOG(("lxzat_caret_ipopen_req,osp_socket_f_open error\r\n"));
						return E_LEC_ERR_NET_SOCKET_INVALID;
                    }
					
                    i_op_status = osp_socket_f_connect(p_hwip_socket->it_socket_fd,p_hwip_socket->pt_peer_ip,p_hwip_socket->ut_peer_port);
                    if (i_op_status != LXZAT_TRUE)
                    {
						lxzat_hwip_socket_f_close(i_socket_id);
						
						OS_DBG_LOG(("lxzat_caret_ipopen_req,osp_socket_f_connect error\r\n"));
						return E_LEC_ERR_NET_CONNECT_TIMEOUT;
                    }

                    p_hwip_socket->it_rxbuf_size = LXZAT_HWIP_TRYREAD_MAX;
                    p_hwip_socket->it_txbuf_size = LXZAT_HWIP_TRYWRITE_MAX;
                    p_hwip_socket->it_socket_phase = E_HWIP_SOCKET_ACTIVE;
                    p_hwip_socket->it_vsp_id = p_cur_spcfg->i_vsp_id;
                    lxzat_task_ipdata_tcpclient_newtask(i_socket_id, p_cur_spcfg->i_vsp_id);
                    break;
                }
            case E_HWIP_LINK_UDP:
                {
					i_op_status = osp_gethostbyname(p_hwip_socket->pt_peer_url ,p_hwip_socket->pt_peer_ip);
                    if(LXZAT_TRUE != i_op_status)
                    {
						lxzat_hwip_socket_f_close(i_socket_id);

                        OS_DBG_LOG(("lxzat_caret_ipopen_req,osp_gethostbyname error\r\n"));
                        return E_LEC_SGCC_DNS_TIMEOUT;
                    }

                    p_hwip_socket->it_socket_fd = osp_socket_f_open(2/*AF_INET*/, 2/*SOCK_DGRAM*/,0);
                    if (p_hwip_socket->it_socket_fd == LXZAT_HWIP_INVALID_FD)
                    {
						lxzat_hwip_socket_f_close(i_socket_id);
						
						OS_DBG_LOG(("lxzat_caret_ipopen_req,osp_socket_f_open error\r\n"));
						return E_LEC_ERR_NET_SOCKET_INVALID;

                    }

                    memset(p_hwip_socket->pt_local_ip, 0, LXZAT_HWIP_IPSTRING_MAX);
                    i_op_status = osp_socket_f_bind(p_hwip_socket->it_socket_fd, p_hwip_socket->pt_local_ip, 0);
                    if (i_op_status != 1)
                    {
                        lxzat_hwip_socket_f_close(i_socket_id);
						
                        OS_DBG_LOG(("lxzat_caret_ipopen_req, osp_socket_f_bind error\r\n"));
                        return E_LEC_ERR_NET_SOCKET_BIND;
                    }

                    p_hwip_socket->it_rxbuf_size = LXZAT_HWIP_TRYREAD_MAX;
                    p_hwip_socket->it_txbuf_size = LXZAT_HWIP_TRYWRITE_MAX;
                    p_hwip_socket->it_socket_phase = E_HWIP_SOCKET_ACTIVE;
                    break;
                }
            default:
                {
					OS_DBG_LOG(("lxzat_caret_ipopen_req,i_link_type=%d\r\n",p_hwip_socket->it_link_type));
					return E_LEC_SGCC_UNKNOWN;

                    break;
                }
            }
            break;
        }
        
    default:
        {
            break;
        }
    }

    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT^IPOPEN".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipopen_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
    
    sint32 i_socket_id = 0;
    sint32 i_read_len = 0;
    sint32 i_view_mode = 0;
    sint32 i_nb_tryread = 0;
    lxzat_hwip_socket_t * p_hwip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipopen_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipopen_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
			sint32 i_op_status = LXZAT_TRUE;
			
            i_socket_id = PARAM1(p_cur_req).it_number;
            if(i_socket_id < 0 || i_socket_id > LXZAT_HWIP_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_caret_ipopen_resp,i_socket_id=%d\r\n",i_socket_id));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_hwip_socket = &(gs_hwip_socket_pool[i_socket_id]);
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: %d,%d",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                i_socket_id,
                i_op_status);

            break;
        }

    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }

    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>,<\"TCP\"|\"UDP\">,<\"IP\">,<Port>",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            
            break;
        }
        
    default:
        {
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT^IPOPEN".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipopen_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT^IPSEND".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipsend_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT^IPSEND".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipsend_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    sint32 i_nb_put = 0;
    sint32 i_socket_id = 0;
    sint32 i_string_type = 0;
    sint32 i_string_len = 0;
    lxzat_hwip_socket_t * p_hwip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipsend_req,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipsend_req,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 2)
            {
                OS_DBG_LOG(("lxzat_caret_ipsend_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
            
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_caret_ipsend_req,param1 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_STRING)
            {
                OS_DBG_LOG(("lxzat_caret_ipsend_req,param3 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_socket_id = PARAM1(p_cur_req).it_number;
            if(i_socket_id < 0 || i_socket_id > LXZAT_HWIP_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_caret_ipsend_req,i_socket_id=%d\r\n",i_socket_id));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_hwip_socket = &(gs_hwip_socket_pool[i_socket_id]);
            if (p_hwip_socket->it_socket_phase != E_HWIP_SOCKET_ACTIVE)
            {
                OS_DBG_LOG(("lxzat_caret_ipsend_req,i_socket_phase=%d\r\n",p_hwip_socket->it_socket_phase));
                return E_LEC_ERR_P_OTHER;
            }
            
            i_string_len = lxz_dstring_getlength(PARAM3(p_cur_req).pt_str);
            if(i_string_len < LXZAT_HWIP_TRYWRITE_MIN || i_string_len > LXZAT_HWIP_TRYWRITE_MAX)
            {
                OS_DBG_LOG(("lxzat_caret_ipsend_req,i_nb_trywrite=%d\r\n",i_string_len));
                return E_LEC_ERR_P_LENGTH;
            }
            
            memset(p_hwip_socket->pt_txbuf, 0, p_hwip_socket->it_txbuf_size);
            lxz_dstring_get(PARAM2(p_cur_req).pt_str, p_hwip_socket->pt_txbuf, p_hwip_socket->it_txbuf_size);
            p_hwip_socket->it_txdata_len = lxz_dstring_getlength(PARAM2(p_cur_req).pt_str);
            
            switch(p_hwip_socket->it_link_type)
            {
            case E_HWIP_LINK_TCP:
                {
                    i_nb_put = osp_socket_f_write(p_hwip_socket->it_socket_fd, p_hwip_socket->pt_txbuf, p_hwip_socket->it_txdata_len);
                    break;
                }
            case E_HWIP_LINK_UDP:
                {
                    i_nb_put = osp_socket_f_writeto(p_hwip_socket->it_socket_fd, 
                        p_hwip_socket->pt_txbuf, 
                        p_hwip_socket->it_txdata_len,
                        p_hwip_socket->pt_peer_ip,
                        p_hwip_socket->ut_peer_port);
                    break;
                }
            default:
                {
                    break;
                }
            }
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT^IPSEND".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipsend_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    sint32 i_nb_put = 0;
    sint32 i_socket_id = 0;
    sint32 i_string_type = 0;
    sint32 i_string_len = 0;
    lxzat_hwip_socket_t * p_hwip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipsend_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipsend_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;

    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            sint32 i_cur_offset = 0;
            
            i_socket_id = PARAM1(p_cur_req).it_number;
            if(i_socket_id < 0 || i_socket_id > LXZAT_HWIP_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_caret_ipsend_resp,i_socket_id=%d\r\n",i_socket_id));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_hwip_socket = &(gs_hwip_socket_pool[i_socket_id]);
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: %d,%d,%d",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                i_socket_id);
            
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>,<\"StringContent\">",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNKNOWN;
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT^IPSEND".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipsend_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT^IPCLOSE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipclose_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT^IPCLOSE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipclose_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
	
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
	
    sint32 i_socket_id = 0;
    sint32 i_view_mode = 0;
    lxzat_hwip_socket_t * p_hwip_socket = NULL;
	
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipclose_req,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
	
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipclose_req,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
	
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 1)
            {
                OS_DBG_LOG(("lxzat_caret_ipclose_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
			
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_caret_ipclose_req,param1 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
			
            i_socket_id = PARAM1(p_cur_req).it_number;
            if(i_socket_id < 0 || i_socket_id > LXZAT_HWIP_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_caret_ipclose_req,i_socket_id=%d\r\n",i_socket_id));
                return E_LEC_ERR_P_RANGE;
            }
			
			lxzat_hwip_socket_f_close(i_socket_id);
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
	
    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT^IPCLOSE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipclose_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
	
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzdata_info_t * p_cur_datacfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;
	
    sint32 i_socket_id = 0;
    lxzat_hwip_socket_t * p_hwip_socket = NULL;
	
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipclose_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
	
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipclose_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
	
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            sint32 i_status_socket = 0;

            p_hwip_socket = &(gs_hwip_socket_pool[0]);
            i_status_socket = 0;
            if (p_hwip_socket->it_socket_phase != E_HWIP_SOCKET_IDLE)
            {
                i_status_socket = 1;
            }

            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: %d",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                i_status_socket);
            
            i_socket_id = 1;
            while (i_socket_id < LXZAT_HWIP_MAX_NUM)
            {
                p_hwip_socket = &(gs_hwip_socket_pool[0]);
                i_status_socket = 0;
                if (p_hwip_socket->it_socket_phase != E_HWIP_SOCKET_IDLE)
                {
                    i_status_socket = 1;
                }
                lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                    LXZAT_RSP_MODE_P0N0,
                    ",%d",
                    i_status_socket);

                i_socket_id = i_socket_id + 1;
            }

            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
			
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNKNOWN;
            break;
        }
    }
	
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT^IPCLOSE".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipclose_reset(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The initialize handler of "AT^IPSENDEX".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipsendex_init(void * pctxt)
{
    return E_LEC_OK;
}

/*
 *  Description:
 *    The request handler of "AT^IPSENDEX".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipsendex_req(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    sint32 i_nb_put = 0;
    sint32 i_socket_id = 0;
    sint32 i_string_type = 0;
    sint32 i_string_len = 0;
    lxzat_hwip_socket_t * p_hwip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipsendex_req,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipsendex_req,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;
    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            if (p_cur_req->it_nb_param != 3)
            {
                OS_DBG_LOG(("lxzat_caret_ipsendex_req,i_nb_param=%d\r\n",p_cur_req->it_nb_param));
                return E_LEC_ERR_P_NB_PARAM;
            }
            
            if (PARAM1_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_caret_ipsendex_req,param1 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM2_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_NUMERIC)
            {
                OS_DBG_LOG(("lxzat_caret_ipsendex_req,param2 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            if (PARAM3_TYPE(p_cur_req) != LXZAT_PARAM_TYPE_STRING)
            {
                OS_DBG_LOG(("lxzat_caret_ipsendex_req,param3 type error!\r\n"));
                return E_LEC_ERR_P_TYPE;
            }
            
            i_socket_id = PARAM1(p_cur_req).it_number;
            if(i_socket_id < 0 || i_socket_id > LXZAT_HWIP_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_caret_ipsendex_req,i_socket_id=%d\r\n",i_socket_id));
                return E_LEC_ERR_P_RANGE;
            }
            
            i_string_type= PARAM2(p_cur_req).it_number;
            if(i_string_type < 0 || i_string_type > 1)
            {
                OS_DBG_LOG(("lxzat_caret_ipsendex_req,i_string_type=%d\r\n",i_string_type));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_hwip_socket = &(gs_hwip_socket_pool[i_socket_id]);
            if (p_hwip_socket->it_socket_phase != E_HWIP_SOCKET_ACTIVE)
            {
                OS_DBG_LOG(("lxzat_caret_ipsendex_req,i_socket_phase=%d\r\n",p_hwip_socket->it_socket_phase));
                return E_LEC_ERR_P_OTHER;
            }
            
            i_string_len = lxz_dstring_getlength(PARAM3(p_cur_req).pt_str);
            if(i_string_len < LXZAT_HWIP_TRYWRITE_MIN || i_string_len > LXZAT_HWIP_TRYWRITE_MAX)
            {
                OS_DBG_LOG(("lxzat_caret_ipsendex_req,i_nb_trywrite=%d\r\n",i_string_len));
                return E_LEC_ERR_P_LENGTH;
            }
            
            memset(p_hwip_socket->pt_txbuf, 0, p_hwip_socket->it_txbuf_size);
            lxz_dstring_get(PARAM3(p_cur_req).pt_str, p_hwip_socket->pt_txbuf, p_hwip_socket->it_txbuf_size);
            p_hwip_socket->it_txdata_len = strlen(p_hwip_socket->pt_txbuf);
            
            if (i_string_type == 1)
            {
                sint32 i_op_status = 0;
                
                i_op_status = lxz_string_f_hex2bin(p_hwip_socket->pt_txbuf, p_hwip_socket->it_txdata_len, 
                    p_hwip_socket->pt_txbuf);
                if (0 == i_op_status)
                {
                    OS_DBG_LOG(("lxzat_caret_ipsendex_req,lxz_string_f_hex2bin error!\r\n"));
                    return E_LEC_ERR_P_OTHER;
                }
                
                p_hwip_socket->it_txdata_len = (p_hwip_socket->it_txdata_len >> 1);
            }

            switch(p_hwip_socket->it_link_type)
            {
            case E_HWIP_LINK_TCP:
                {
                    i_nb_put = osp_socket_f_write(p_hwip_socket->it_socket_fd, p_hwip_socket->pt_txbuf, p_hwip_socket->it_txdata_len);
                    break;
                }
            case E_HWIP_LINK_UDP:
                {
                    i_nb_put = osp_socket_f_writeto(p_hwip_socket->it_socket_fd, 
                        p_hwip_socket->pt_txbuf, 
                        p_hwip_socket->it_txdata_len,
                        p_hwip_socket->pt_peer_ip,
                        p_hwip_socket->ut_peer_port);
                    break;
                }
            default:
                {
                    break;
                }
            }
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNSUPPORTED;
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The response handler of "AT^IPSENDEX".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipsendex_resp(void * pctxt)
{
    sint32 i_err_code = E_LEC_OK;
    
    sint32 i_req_type = LXZAT_REQ_TYPE_ERR;
    lxzat_req_t * p_cur_req = NULL;
    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_context_t * p_lxzat_ctxt = (lxzat_context_t *)pctxt;

    sint32 i_nb_put = 0;
    sint32 i_socket_id = 0;
    sint32 i_string_type = 0;
    sint32 i_string_len = 0;
    lxzat_hwip_socket_t * p_hwip_socket = NULL;
    
    if (p_lxzat_ctxt == NULL)
    {
        OS_DBG_LOG(("lxzat_caret_ipsendex_resp,p_lxzat_ctxt is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    p_cur_req = p_lxzat_ctxt->pt_req_data;
    p_cur_spcfg = lxzat_spcomm_f_get(p_lxzat_ctxt->it_vsp_id);
    if ((p_cur_req == NULL) || (p_cur_spcfg == NULL))
    {
        OS_DBG_LOG(("lxzat_caret_ipsendex_resp,p_cur_req or p_cur_spcfg is NULL!\r\n"));
        return E_LEC_ERR_UNKNOWN;
    }
    
    i_req_type = p_cur_req->it_req_type;

    switch(i_req_type)
    {
    case LXZAT_REQ_TYPE_SET:
        {
            sint32 i_cur_offset = 0;
            
            i_socket_id = PARAM1(p_cur_req).it_number;
            if(i_socket_id < 0 || i_socket_id > LXZAT_HWIP_MAX_NUM)
            {
                OS_DBG_LOG(("lxzat_caret_ipsendex_resp,i_socket_id=%d\r\n",i_socket_id));
                return E_LEC_ERR_P_RANGE;
            }
            
            p_hwip_socket = &(gs_hwip_socket_pool[i_socket_id]);
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: %d,%d,%d",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword,
                i_socket_id,
                p_hwip_socket->it_txdata_len,
                i_cur_offset);
            
            break;
        }
    case LXZAT_REQ_TYPE_READ:
        {
            break;
        }
    case LXZAT_REQ_TYPE_TEST:
        {
            lxzat_rsp_f_printf(p_lxzat_ctxt->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "%s: <SocketID>,<mode>,<\"StringContent\">",
                p_lxzat_ctxt->pt_ai_cfg->pt_ai_keyword);
            
            break;
        }
    default:
        {
            i_err_code = E_LEC_ERR_UNKNOWN;
            break;
        }
    }
    
    return i_err_code;
}

/*
 *  Description:
 *    The reset handler of "AT^IPSENDEX".
 *  Param: pctxt, the pointer of AT command context;
 *  Return: Operating results;
 *  Note: NONE
 */
static sint32 lxzat_caret_ipsendex_reset(void * pctxt)
{
    return E_LEC_OK;
}

static sint32 lxzat_callback_ipinit_f_exec(sint32 p1, sint32 p2)
{
    sint32 i_op_status = 1;
    sint32 i_id_vspctxt = 0;
    sint32 i_id_pdpctxt = 0;
    sint32 i_id_sgccpdpctxt = 0;

    sint32 i_cur_pdpstatus = 0;

    lxzat_spcfg_t * p_cur_spcfg = NULL;
    lxzat_nvcfg_t * p_cur_nvcfg = NULL;
    sint08 ll_buf_ipaddr [LXZAT_MAX_LEN_IPV4];

    i_id_vspctxt = p1;
    p_cur_spcfg = lxzat_spcomm_f_get(i_id_vspctxt);
    p_cur_nvcfg = p_cur_spcfg->pt_nv_cfg;
    if (p_cur_spcfg == NULL)
    {
        return 0;
    }

    i_id_pdpctxt = p2;
    lxzat_pdpinfo_f_getstatus(i_id_pdpctxt, &i_cur_pdpstatus);
    if (E_PDP_STATUS_ACTIVATED == i_cur_pdpstatus)
    {
        i_op_status = 0;
        i_id_sgccpdpctxt = i_id_pdpctxt;
        lxzat_pdpinfo_f_getipaddress(i_id_pdpctxt, ll_buf_ipaddr);
        if(gs_hwip_urcflag == 1)
        {
            lxzat_urc_f_printf(i_id_vspctxt, 
                LXZAT_RSP_MODE_P1N1, 
                "^IPINIT: %d,%d,\"%s\"", 
                i_id_sgccpdpctxt, 1, ll_buf_ipaddr);
        }
    }

    return i_op_status;
}

static sint32 lxzat_callback_ipinit_f_exit(sint32 p1, sint32 p2)
{
    OS_DBG_LOG(("lxzat:lxzat_callback_ipinit_f_exit\r\n"));
    return 1;
}

/*
 *  Description:
 *    new task, ipinit task.
 *  Param: i_id_vspctxt, the ID of serial-port;
 *  Param: i_id_vspctxt, the ID of pdp-context;
 *
 *  Return: status of operating.
 */
static sint32 lxzat_task_ipinit_newtask(sint32 i_id_vspctxt, sint32 i_id_pdpctxt)
{
    sint32 i_op_status = 0;

    lxzat_task_t *p_new_task = NULL;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_pdpinfo_t* p_cur_pdpinfo = NULL;

    p_cur_spcfg = lxzat_spcomm_f_get(i_id_vspctxt);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_ipinit_newtask,i_id_vspctxt=%d\r\n", i_id_vspctxt));
        return i_op_status;
    }

    if ((i_id_pdpctxt < 0) || (i_id_pdpctxt > 15))
    {
        OS_DBG_LOG(("lxzat:lxzat_task_ipinit_newtask,i_id_pdpctxt=%d\r\n", i_id_pdpctxt));
        return i_op_status;
    }

    OS_DBG_LOG(("lxzat:lxzat_task_ipinit_newtask,entry\r\n"));
    OS_DBG_LOG(("lxzat:lxzat_task_ipinit_newtask,i_id_vspctxt=%d,i_id_pdpctxt=%d\r\n", i_id_vspctxt, i_id_pdpctxt));
    p_new_task = (lxzat_task_t *)malloc(sizeof(lxzat_task_t));
    if(p_new_task == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_ipinit_newtask,p_new_task==NULL!\r\n"));
        return i_op_status;
    }

    i_op_status = 1;
    memset(p_new_task, 0, sizeof(lxzat_task_t));
    p_new_task->fp_exec = lxzat_callback_ipinit_f_exec;
    p_new_task->fp_exit = lxzat_callback_ipinit_f_exit;
    p_new_task->sparam1 = i_id_vspctxt;
    p_new_task->sparam2 = i_id_pdpctxt;
    p_new_task->next = NULL;
    lxzat_task_f_create(p_new_task);

    return i_op_status;
}

static sint32 lxzat_hwip_socket_f_close(sint32 i_socket_id)
{
    sint32 i_op_status = LXZAT_FALSE;
	lxzat_hwip_socket_t * p_hwip_socket = NULL;

	if(i_socket_id < 0 || i_socket_id > LXZAT_HWIP_MAX_NUM)
	{
		OS_DBG_LOG(("lxzat_hwip_socket_f_close,i_socket_id=%d\r\n", i_socket_id));
		return i_op_status;
	}

	p_hwip_socket = p_hwip_socket = &(gs_hwip_socket_pool[i_socket_id]);
	if(p_hwip_socket->pt_rxbuf != NULL)
	{
		free(p_hwip_socket->pt_rxbuf);
		p_hwip_socket->pt_rxbuf = NULL;
	}
	
	if(p_hwip_socket->pt_txbuf != NULL)
	{
		free(p_hwip_socket->pt_txbuf);
		p_hwip_socket->pt_txbuf = NULL;
	}
	
	if(p_hwip_socket->pt_peer_ip != NULL)
	{
		free(p_hwip_socket->pt_peer_ip);
		p_hwip_socket->pt_peer_ip = NULL;
	}
	
	if(p_hwip_socket->pt_peer_url != NULL)
	{
		free(p_hwip_socket->pt_peer_url);
		p_hwip_socket->pt_peer_url = NULL;
	}

	if(p_hwip_socket->pt_local_ip!= NULL)
	{
		free(p_hwip_socket->pt_local_ip);
		p_hwip_socket->pt_local_ip = NULL;
	}

	if(p_hwip_socket->it_socket_fd != LXZAT_HWIP_INVALID_FD)
	{
		osp_socket_f_close(p_hwip_socket->it_socket_fd);
		p_hwip_socket->it_socket_fd = LXZAT_HWIP_INVALID_FD;
	}
	
	memset(p_hwip_socket, 0, sizeof(lxzat_hwip_socket_t));
	p_hwip_socket->it_socket_fd = LXZAT_HWIP_INVALID_FD;
	i_op_status = LXZAT_TRUE;

	return i_op_status;
}

static sint32 lxzat_callback_ipdata_tcpclient_f_exec(sint32 p1, sint32 p2)
{
    sint32 i_op_status = 0;

    sint32 i_nb_fds = 0;
    sint32 i_nb_bytes_read = 0;
    sint32 i_nb_bytes_available = 0;
    
    sint32 i_id_socket = 0;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_hwip_socket_t * p_hwip_socket = NULL;
    
    i_id_socket = p1;
    if ((i_id_socket < 0) || (i_id_socket > LXZAT_HWIP_MAX_NUM))
    {
        return i_op_status;
    }

    p_hwip_socket = &(gs_hwip_socket_pool[i_id_socket]);
    if (p_hwip_socket == NULL)
    {
        OS_DBG_LOG(("lxzat_callback_ipdata_tcpclient_f_exec,i_id_socket=%d,p_hwip_socket==NULL\r\n", i_id_socket));
        return i_op_status;
    }

    p_cur_spcfg = lxzat_spcomm_f_get(p_hwip_socket->it_vsp_id);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat_callback_ipdata_tcpclient_f_exec,i_id_socket=%d,p_cur_spcfg==NULL\r\n", i_id_socket));
        return i_op_status;
    }
    
    if (p_hwip_socket->it_socket_fd == 0)
    {
        OS_DBG_LOG(("lxzat_callback_ipdata_tcpclient_f_exec,it_socket_fd=%d\r\n", p_hwip_socket->it_socket_fd));
        return i_op_status;
    }

    if (p_hwip_socket->it_socket_phase <= E_HWIP_SOCKET_CONNECTING)
    {
        OS_DBG_LOG(("lxzat_callback_ipdata_tcpclient_f_exec,it_socket_phase=%d\r\n", p_hwip_socket->it_socket_phase));
        return i_op_status;
    }

    if (p_hwip_socket->it_link_type != E_HWIP_LINK_TCP)
    {
        OS_DBG_LOG(("lxzat_callback_ipdata_tcpclient_f_exec,it_net_type=%d\r\n", p_hwip_socket->it_link_type));
        return i_op_status;
    }

    if (   (p_hwip_socket->it_socket_phase == E_HWIP_SOCKET_ACTIVE)
        || (p_hwip_socket->it_socket_phase == E_HWIP_SOCKET_SENDING))
    {
        sint32 i_nb_bytes_available = 0;
        i_nb_bytes_available = osp_socket_f_getavailable(p_hwip_socket->it_socket_fd);
        if (i_nb_bytes_available > 0)
        {
            memset(p_hwip_socket->pt_rxbuf,0,LXZAT_HWIP_TRYREAD_DEF);
            i_nb_bytes_read = osp_socket_f_read(p_hwip_socket->it_socket_fd,
                p_hwip_socket->pt_rxbuf,LXZAT_HWIP_TRYREAD_DEF);
            
            lxzat_rsp_f_printf(p_hwip_socket->it_vsp_id,
                LXZAT_RSP_MODE_P1N0,
                "^IPDATA: %d,%d,",
                i_id_socket,
                i_nb_bytes_read);

            lxzat_spcomm_f_writebyid(p_hwip_socket->it_vsp_id,
                p_hwip_socket->pt_rxbuf, i_nb_bytes_read);
            lxzat_rsp_f_printf(p_hwip_socket->it_vsp_id,
                LXZAT_RSP_MODE_P0N1,"");
            lxzat_spcomm_f_flush(p_hwip_socket->it_vsp_id);
        }

        i_nb_fds = osp_socket_f_select(p_hwip_socket->it_socket_fd, OSP_EVENT_READ, 0);
        if (i_nb_fds > 0)
        {
            i_nb_bytes_available = osp_socket_f_getavailable(p_hwip_socket->it_socket_fd);
            if (i_nb_bytes_available == 0)
            {
                p_hwip_socket->it_socket_phase = E_HWIP_SOCKET_CLOSING;
                OS_DBG_LOG(("lxzat_callback_ipdata_tcpclient_f_exec,i_id_socket=%d, closed!\r\n", i_id_socket));
            }
        }
    }

    if (p_hwip_socket->it_socket_phase == E_HWIP_SOCKET_CLOSING)
    {
        i_nb_bytes_available = osp_socket_f_getavailable(p_hwip_socket->it_socket_fd);
        if (i_nb_bytes_available <= 0)
        {
            if(gs_hwip_urcflag == 1)
            {
                lxzat_urc_f_printf(p_hwip_socket->it_vsp_id, LXZAT_RSP_MODE_P1N1, "^IPCLOSE: %d", i_id_socket);
            }

            lxzat_spcomm_f_clear(p_hwip_socket->it_vsp_id);
            lxzat_spcomm_f_ChangeWorkMode(p_hwip_socket->it_vsp_id,
                E_LSMX_ATC, LXZAT_END_CHAR_CR, LXZAT_END_CHAR_LF);
            lxzat_hwip_socket_f_close(i_id_socket);
            OS_DBG_LOG(("lxzat_callback_ipdata_tcpclient_f_exec,i_id_socket=%d, closed!\r\n", i_id_socket));
        }
    }

    i_op_status = 1;
    return i_op_status;
}

static sint32 lxzat_callback_ipdata_tcpclient_f_exit(sint32 p1, sint32 p2)
{
    OS_DBG_LOG(("lxzat:lxzat_callback_ipdata_tcpclient_f_exit\r\n"));
    return 1;
}

/*
 *  Description:
 *    new task, ipdata-client task.
 *  Param: i_id_vspctxt, the ID of serial-port;
 *  Param: i_id_vspctxt, the ID of pdp-context;
 *
 *  Return: status of operating.
 */
static sint32 lxzat_task_ipdata_tcpclient_newtask(sint32 i_id_socket, sint32 i_id_vspctxt)
{
    sint32 i_op_status = 0;

    lxzat_task_t *p_new_task = NULL;
    lxzat_spcfg_t* p_cur_spcfg = NULL;
    lxzat_pdpinfo_t* p_cur_pdpinfo = NULL;

    p_cur_spcfg = lxzat_spcomm_f_get(i_id_vspctxt);
    if (p_cur_spcfg == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_ipdata_newtask,i_id_vspctxt=%d\r\n", i_id_vspctxt));
        return i_op_status;
    }

    OS_DBG_LOG(("lxzat:lxzat_task_ipdata_newtask,entry\r\n"));
    OS_DBG_LOG(("lxzat:lxzat_task_ipdata_newtask,i_id_socket=%d,i_id_vspctxt=%d\r\n", i_id_socket, i_id_vspctxt));
    p_new_task = (lxzat_task_t *)malloc(sizeof(lxzat_task_t));
    if(p_new_task == NULL)
    {
        OS_DBG_LOG(("lxzat:lxzat_task_ipdata_newtask,p_new_task==NULL!\r\n"));
        return i_op_status;
    }

    i_op_status = 1;
    memset(p_new_task, 0, sizeof(lxzat_task_t));
    p_new_task->fp_exec = lxzat_callback_ipdata_tcpclient_f_exec;
    p_new_task->fp_exit = lxzat_callback_ipdata_tcpclient_f_exit;
    p_new_task->sparam1 = i_id_socket;
    p_new_task->sparam2 = i_id_vspctxt;
    p_new_task->next = NULL;
    lxzat_task_f_create(p_new_task);

    return i_op_status;
}

